package zjh_20230403;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Demo01 {
    public static void main(String[] args) {

        PreparedStatement preparedStatement = null;
        ResultSet r = null;
        List<Teacher> list = new ArrayList<>();
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/school?user=root&password=");
            String sql = "SELECT * FROM teacher";
            preparedStatement = conn.prepareStatement(sql);
            r = preparedStatement.executeQuery();
            while(r.next()){
                list.add((Teacher) r);
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


        HSSFWorkbook sheets = new HSSFWorkbook();
        HSSFSheet sheet = sheets.createSheet("教师表");

        HSSFRow row = sheet.createRow(0);
        row.createCell(0).setCellValue("教师编号");
        row.createCell(1).setCellValue("教师姓名");


        for (int i = 0; i <list.size(); i++) {
            HSSFRow row1 = sheet.createRow(i + 1);
//            row1.getCell()

        }

        try {
            FileOutputStream fileOutputStream = new FileOutputStream("src/io/first.xls");
            sheets.write(fileOutputStream);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
